package com.example.leetcode.stack;

import java.util.Stack;

class MyQueue {

    Stack<Integer> stackOne = new Stack<>();
    Stack<Integer> stackTwo = new Stack<>();

    public MyQueue() {

    }

    public void push(int x) {
        stackOne.add(x);
    }

    public int pop() {
        if (stackTwo.isEmpty()) {
            if (stackOne.isEmpty()) {
                return -1;
            } else {
                while (!stackOne.isEmpty()) {
                    stackTwo.push(stackOne.pop());
                }
            }
        }
        return stackTwo.pop();
    }

    public int peek() {
        if (stackTwo.isEmpty()) {
            if (stackOne.isEmpty()) {
                return -1;
            } else {
                while (!stackOne.isEmpty()) {
                    stackTwo.push(stackOne.pop());
                }
            }
        }
        return stackTwo.peek();
    }

    public boolean empty() {
        return stackOne.isEmpty() && stackTwo.isEmpty();
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue obj = new MyQueue();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.peek();
 * boolean param_4 = obj.empty();
 */

public class leetcode232 {
    public static void main(String[] args) {
        MyQueue myQueue = new MyQueue();
        myQueue.push(1); // queue is: [1]
        myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
        System.out.println(myQueue.peek()); // return 1
        System.out.println(myQueue.pop()); // return 1, queue is [2]
        System.out.println(myQueue.empty()); // return false
    }
}
